//
//  CSNewOrderManageVC.m
//  ProjectforHDX
//
//  Created by yinda on 16/8/22.
//  Copyright © 2016年 H.DX. All rights reserved.
//

// 客户备件管理
#import "CSNewOrderManageVC.h"
#import "CSNewOrderCell.h"
#import "CSNewOrderFirstCell.h"
#import "CSNewOrderUseRepairsCell.h"
#import "CSNewOrderMessageCell.h"
#import "CSNewOrderReplaceCell.h"
#import "CSNewOrderLogisticsCell.h"
#import "CSNewOrderDeliveryCell.h"
#import "CNewOrderFaultyPartsVC.h"     //获取故障件名称
#import "FailurePartsModel.h"
#import "ConsigneeListVC.h"

#import "MHScanViewController.h"

@interface CSNewOrderManageVC ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,PXAlertViewDelegate,UITextViewDelegate,UIActionSheetDelegate,UIImagePickerControllerDelegate,MWPhotoBrowserDelegate,UITextViewDelegate>
{
    UITableView *tabelView;     //备件管理服务
    NSMutableDictionary *managerPostDic; // 管理提交数据
    NSMutableArray *receiptArray;        //收货信息左边
    NSMutableArray *pieceArray;         // 用来存放右边信息
    NSMutableDictionary *baseDataDic;//缓存一组数据，用户数据，右边
    NSMutableDictionary *dataDic;  //收货信息
    NSString *remark;  //备注
    NSInteger delivery;             // 是否同时取件
    UIAlertController *alertView;  //选择器
    NSArray *myConsigneesArray;    // 获取的客户联系人信息
    UIView *shadowView;            // 阴影
    NSString *timeInput;   //故障件取件时间
}

@property (nonatomic, strong) UIView *maskView;

@end

@implementation CSNewOrderManageVC{
    UIDatePicker *datePicker;
    UIToolbar *toolBar;
    UITextField *currentTextField;
}

- (void)getDefaultContactsAndAddress
{
    [AFHttpTool postJsonDatawithUrl:@"getAddresses" parameters:nil success:^(id responseObject) {
        
        if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
            NSArray *array = [responseObject objectForKey:@"data"];
            NSLog(@"地址为%@",array);
            NSMutableArray *actionArray = [[NSMutableArray alloc]init];
            for (int i = 0; i < array.count; i++) {
                [actionArray addObject:array[i][@"address"]];
            }
            if (actionArray.count > 0) {
                [dataDic setValue:actionArray[0] forKey:@"address"];
            }
            [tabelView reloadData];
        }else {
            [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
    }];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self dataConfig];
    
    [self getDefaultContactsAndAddress];

    [self viewFound];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    //获取通知中心单例对象
    NSNotificationCenter * centerFault = [NSNotificationCenter defaultCenter];
    //添加当前类对象为一个观察者，name和object设置为nil，表示接收一切通知
    [centerFault addObserver:self selector:@selector(notice:) name:@"fault" object:nil];
    
    [tabelView reloadData];
}

-(void)notice:(NSNotification *)sender{
    
    
    NSLog(@"传过来的%@",sender.userInfo);
    
    NSInteger faulttag = [sender.userInfo[@"tag"] intValue];
    if (faulttag / 100 == 3) {
        
        [pieceArray[faulttag  % 100 - 1] setValue:sender.userInfo[@"name"] forKey:@"name"];
        [pieceArray[faulttag  % 100 - 1] setValue:sender.userInfo[@"code"] forKey:@"code"];
        [pieceArray[faulttag  % 100 - 1] setValue:sender.userInfo[@"is_version"] forKey:@"is_version"];
        [pieceArray[faulttag  % 100 - 1] setValue:sender.userInfo[@"faultid"] forKey:@"id"];
        [pieceArray[faulttag  % 100 - 1] setValue:sender.userInfo[@"version"] forKey:@"versionCode"];
        [pieceArray[faulttag  % 100 - 1] setValue:sender.userInfo[@"sn"] forKey:@"sn"];

        [pieceArray[faulttag  % 100 - 1] setValue:[UtilCheck language:@"order.no"] forKey:@"isUseOneLine"];
        [pieceArray[faulttag  % 100 - 1] setValue:sender.userInfo[@"faultPartType"] forKey:@"faultPartType"];
        
        
        NSLog(@"%@",pieceArray);
        

    }
    if (faulttag > 1000) {
        
        
        NSLog(@"接收的%@",pieceArray);
        
        [pieceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"name"] forKey:@"oneLineName"];
        [pieceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"code"] forKey:@"oneLineCode"];
        [pieceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"faultid"] forKey:@"oneLineID"];
        [pieceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"version"] forKey:@"oneLineOneLineVersion"];
        [pieceArray[faulttag / 100 - 10] setValue:sender.userInfo[@"sn"] forKey:@"oneLineOneLineSN"];

    }

    
}

- (void)RightButton
{
    NSLog(@"?");
    ConsigneeListVC *vc = [[ConsigneeListVC alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

#pragma mark 构建界面
- (void)viewFound{
    
    // 标题
    RZCustomLable *titleLabel = [[RZCustomLable alloc] initWithFrame:CGRectMake(0, 0, 80, 44)];
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    titleLabel.textColor = [UIColor whiteColor];
    titleLabel.text = [UtilCheck language:@"main.creatingOrders"];
    self.navigationItem.titleView = titleLabel;
    
    [self.labnav setFont:NavFontSize];
    [self.labnav setTextColor:[UIColor whiteColor]];
    self.labnav.backgroundColor = [UIColor clearColor];

    self.view.backgroundColor = [UtilCheck hexStringToColor:@"f1f8fd" alpha:1];
    
    
    tabelView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, self.view.bounds.size.height - 110) style:(UITableViewStyleGrouped)];
    
    tabelView.backgroundColor = [UtilCheck hexStringToColor:@"f4f8fb" alpha:1];
    tabelView.delegate = self;
    tabelView.dataSource = self;
    tabelView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, tabelView.bounds.size.width, 0.01f)];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderFirstCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderFirstCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderUseRepairsCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderUseRepairsCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderMessageCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderMessageCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderReplaceCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderReplaceCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderLogisticsCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderLogisticsCell"];
    [tabelView registerNib:[UINib nibWithNibName:@"CSNewOrderDeliveryCell" bundle:nil] forCellReuseIdentifier:@"CSNewOrderDeliveryCell"];
    
    tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:tabelView];
    // 标题
    if (self.dict != nil) {
        titleLabel.text = [UtilCheck language:@"main.orderUpdate"];
    }else {
        titleLabel.text = [UtilCheck language:@"main.creatingOrders"];
    }
    // 修改订单头
    if (self.order == 1) {
        tabelView.tableHeaderView = ({
            UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.frame.size.width, 60)];
            header.backgroundColor = [UtilCheck hexStringToColor:@"1a56bc" alpha:1];
            
            RZCustomLable *orderIDLabel = [[RZCustomLable alloc]initWithFrame:CGRectMake(5, 5, 200, 20)];
            orderIDLabel.text = [NSString stringWithFormat:@"订单号: %@",self.dict[@"orderStatus"][@"orderCode"]];
            orderIDLabel.textColor = [UIColor whiteColor];
            orderIDLabel.font = [UIFont systemFontOfSize:12];
            [header addSubview:orderIDLabel];
            RZCustomLable *ordersTiemLabel = [[RZCustomLable alloc]initWithFrame:CGRectMake(5, 25, 200, 20)];
            ordersTiemLabel.text = [NSString stringWithFormat:@"下单时间: %@",self.dict[@"orderStatus"][@"orderTime"]];
            ordersTiemLabel.textColor = [UIColor whiteColor];
            ordersTiemLabel.font = [UIFont systemFontOfSize:12];
            [header addSubview:ordersTiemLabel];
            RZCustomLable *stateLabel = [[RZCustomLable alloc]initWithFrame:CGRectMake(tabelView.bounds.size.width - 70, 5, 40, 40)];
            stateLabel.backgroundColor = [UtilCheck hexStringToColor:@"ff9c5a" alpha:1];
            stateLabel.text = self.dict[@"orderStatus"][@"statusName"];
            stateLabel.textColor = [UIColor whiteColor];
            stateLabel.font = [UIFont systemFontOfSize:13];
            stateLabel.textAlignment = NSTextAlignmentCenter;
            stateLabel.layer.cornerRadius = 20;
            
            stateLabel.layer.masksToBounds = YES;
            
            
            [header addSubview:stateLabel];
            
            header;
        });
    }
    //提交
    RZCustomButtom *commit = [[RZCustomButtom alloc]init];
    commit.frame = CGRectMake((tabelView.bounds.size.width - (tabelView.bounds.size.width - 30)) / 2,SCREEN_HEIGHT - 108,tabelView.bounds.size.width - 30,40);
    [commit setBackgroundImage:BDFILEIMAGENAEM(@"Order/btn_submit.png") forState:(UIControlStateNormal)];
    [commit setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
    commit.titleLabel.font = [UIFont systemFontOfSize:16];
    [commit setTitle:[UtilCheck language:@"main.submitOrder"] forState:(UIControlStateNormal)];
    [commit addTarget:self action:@selector(commitGoto) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:commit];
    
    if (self.order == 1) {
        
        NSLog(@"%@",self.dict);
        
        //收货信息
        dataDic[@"user"] = self.dict[@"receiver"][@"userID"];
        dataDic[@"address"] = self.dict[@"receiver"][@"address"];
        dataDic[@"tel"] = [NSString stringWithFormat:@"%@ %@",self.dict[@"receiver"][@"name"],self.dict[@"receiver"][@"tel"]];
        dataDic[@"time"] = self.dict[@"receiver"][@"arriveTime"];
        
        
//        customerServiceDic[@"customerTime"] = self.dict[@"customerService"][@"customerTime"];
//        customerServiceDic[@"customerID"] = self.dict[@"customerService"][@"customerID"];
        
        // 故障件信息
        for (NSDictionary *dic in self.dict[@"parts"][@"faultParts"]) {
            
            NSDictionary *myDataDic = dic[@"faultPart"];
            
            NSMutableDictionary *DataDic = [[NSMutableDictionary alloc]init];
            if ([myDataDic objectForKey:@"plateID"] == nil) {
                [DataDic setValue:@"" forKey:@"id"];
            }else {
                [DataDic setValue:[myDataDic objectForKey:@"plateID"] forKey:@"id"];
            }
            [DataDic setValue:[myDataDic objectForKey:@"rma"] forKey:@"rma"];
            [DataDic setValue:[myDataDic objectForKey:@"plateName"] forKey:@"name"];
            [DataDic setValue:[myDataDic objectForKey:@"plateCode"] forKey:@"code"];
            [DataDic setValue:[myDataDic objectForKey:@"is_version"] forKey:@"is_version"];
            [DataDic setValue:[myDataDic objectForKey:@"plateVersion"] forKey:@"versionCode"];
            [DataDic setValue:[myDataDic objectForKey:@"faultPartType"] forKey:@"faultPartType"];
            [DataDic setValue:[myDataDic objectForKey:@"plateSn"] forKey:@"sn"];
            [DataDic setValue:[myDataDic objectForKey:@"number"] forKey:@"number"];

            [DataDic setValue:[dic objectForKey:@"detail"] forKey:@"detail"];
            [DataDic setValue:[myDataDic objectForKey:@"stationName"] forKey:@"stationName"];
            [DataDic setValue:[myDataDic objectForKey:@"siteID"] forKey:@"siteID"];
            NSString *height = dic[@"isUseOneLine"];
            
            [DataDic setValue:height forKey:@"isUseOneLine"];
    
            if ([height isEqualToString:[UtilCheck language:@"order.yes"]]) {
                NSDictionary *oneLineDic = dic[@"oneLineInfo"];
                NSLog(@"%@",oneLineDic);
                [DataDic setValue:[oneLineDic objectForKey:@"oneLineName"] forKey:@"oneLineName"];
                [DataDic setValue:[oneLineDic objectForKey:@"oneLineCode"] forKey:@"oneLineCode"];
                [DataDic setValue:[oneLineDic objectForKey:@"oneLineVersion"] forKey:@"oneLineOneLineVersion"];
                [DataDic setValue:[oneLineDic objectForKey:@"oneLineSN"] forKey:@"oneLineOneLineSN"];
                [DataDic setValue:[oneLineDic objectForKey:@"id"] forKey:@"oneLineID"];
                
            }
            
            NSLog(@"%@",DataDic);
            
            [pieceArray addObject:DataDic];
        }
        
        //是否同时取件
        delivery = [self.dict[@"isSameTime"]intValue];
        //备注
        remark = self.dict[@"remark"];
    }

    
}


#pragma mark  数据初始化
- (void)dataConfig{
    
    receiptArray = [[NSMutableArray alloc]init];
    
    THUserInfoModel *userModel=[THMangerTool getAccountInfo];
    receiptArray = [[NSMutableArray alloc]initWithObjects:[UtilCheck language:@"order.receive.address"],[UtilCheck language:@"order.receiver.contacts"],[UtilCheck language:@"order.order.time"],[UtilCheck language:@"order.wish.arrive.time"], nil];
    if ([userModel.is_service_time isEqualToString:@"1"]) {
        [receiptArray addObject:[UtilCheck language:@"order.service.time"]];
    }
    baseDataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"rma",@"",@"id",@"",@"name",@"",@"code",@"",@"versionCode",@"",@"sn",@"1",@"number",@"",@"detail",@"",@"stationName",@"",@"siteID",@"",@"faultPartType",[UtilCheck language:@"order.no"],@"isUseOneLine",@"",@"is_version", nil];
    dataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"address",@"",@"time",@"",@"user",@"",@"tel",@"",@"service_time", nil];
    remark = @"";
    pieceArray = [[NSMutableArray alloc]init];
    if (self.order == 1) {
        
    }else {
        [pieceArray addObject:baseDataDic];
    }
}
#pragma mark TableViewDataSource  TableViewDelegate
// 四个组
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  
        return 4;

}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    if (indexPath.section == 3) {
        return 60;
    }else if (indexPath.section == 1) {
        
        if (self.order == 1) {
            NSLog(@"%ld ",(long)indexPath.row);
            
            NSString *height = self.dict[@"parts"][@"faultParts"][indexPath.row][@"isUseOneLine"];
            
            NSLog(@"%@",self.dict[@"parts"][@"faultParts"][indexPath.row][@"isUseOneLine"]);
            
            if ([height isEqualToString:[UtilCheck language:@"order.no"]]) {
                return 382;
            }else {
                return 558;
            }
        }else {
            NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithDictionary:pieceArray[indexPath.row]];
            if ([[dic objectForKey:@"isUseOneLine"] isEqualToString:[UtilCheck language:@"order.no"]]) {
                return 382;
            }else {
                return 558;
            }
            
        }
        
    }else if (indexPath.section == 2){
              if (delivery == 0){
                 return 88;
              }else if (delivery == 1){
                 return 44;
              }
        }
        return 44;
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
        if (section == 0) {
            
            
            return receiptArray.count;
        }else if (section == 1) {
            if (self.order == 1) {
                NSArray *arr = self.dict[@"parts"][@"faultParts"];
                return arr.count;
            }else {
                return pieceArray.count;
            }
        }else if (section == 2){
            return 1;
        }else if (section == 3){
            return 1;
        }
    
    return 0;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        NSInteger section = indexPath.section;
        if (section == 0) {
            CSNewOrderCell * ordercell = [tableView dequeueReusableCellWithIdentifier:@"CSNewOrderCell" forIndexPath:indexPath];
            ordercell.selectionStyle = UITableViewCellSelectionStyleNone;
            ordercell.messageLabel.hidden = NO;
            ordercell.nemeLabel.text = receiptArray[indexPath.row];
            ordercell.messageLabel.tag = section + indexPath.row;
            if (indexPath.row == 0) {
                NSLog(@"%@",dataDic[@"user"]);
                ordercell.requiredLabel.hidden = NO;
                ordercell.messageLabel.text = dataDic[@"address"];
            }else if (indexPath.row == 3) {
                ordercell.requiredLabel.hidden = YES;
                ordercell.messageLabel.text = dataDic[@"time"];
            }else if (indexPath.row == 1) {
                ordercell.requiredLabel.hidden = NO;
                ordercell.messageLabel.text = dataDic[@"tel"];
            }else if (indexPath.row == 4) {
                ordercell.requiredLabel.hidden = YES;
                ordercell.messageLabel.text = dataDic[@"service_time"];
            }else if (indexPath.row == 2) {
                ordercell.requiredLabel.hidden = YES;
                ordercell.messageLabel.text = dataDic[@"customerOrderTime"];
            }
            
            if (self.dict != nil) {
                
                ordercell.messageLabel.userInteractionEnabled = NO;
            }else {
                
                ordercell.messageLabel.userInteractionEnabled = YES;
            }
            UITapGestureRecognizer *Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
            [ordercell.messageLabel addGestureRecognizer:Recognizer];
            Recognizer.view.tag = 101 + indexPath.row;
            ordercell.arrowImageView.hidden = NO;
            ordercell.arrowImageView.image = BDFILEIMAGENAEM(@"UserCenter/arrow.png");
            
            ordercell.lineLabel = [[UILabel alloc]init];
            [ordercell.lineLabel setFrame:CGRectMake(0, 43.5, tabelView.width, 0.5)];
            [ordercell.lineLabel setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [ordercell addSubview:ordercell.lineLabel];
            if (indexPath.row == 0) {
                RZCustomLable *myLable = [[RZCustomLable alloc]init];
                [myLable setFrame:CGRectMake(0, 0, tabelView.width, 0.5)];
                [myLable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
                [ordercell addSubview:myLable];
            }
            
            return ordercell;
            
        }else if (section == 1){
            NSMutableDictionary *dic = [[NSMutableDictionary alloc]initWithDictionary:pieceArray[indexPath.row]];
            self.order = 0;
            if ([[dic objectForKey:@"isUseOneLine"] isEqualToString:[UtilCheck language:@"order.no"]]) {
                CSNewOrderFirstCell *firstCell = [tabelView dequeueReusableCellWithIdentifier:@"CSNewOrderFirstCell" forIndexPath:indexPath];
                firstCell.selectionStyle = UITableViewCellSelectionStyleNone;
                if (self.dict != nil) {
            
                    firstCell.numberTextField.userInteractionEnabled = NO;
                    firstCell.deleteButton.hidden = YES;

                }else {
                    if (indexPath.row == 0) {
                        firstCell.deleteButton.hidden = YES;
                    }else {
                        firstCell.deleteButton.hidden = NO;
                    }
                }
                
                NSString *faultPartTypeString = [NSString stringWithFormat:@"%@",[pieceArray[indexPath.row] objectForKey:@"faultPartType"]];
            NSLog(@"====================================================================================%@",faultPartTypeString);

                if ([faultPartTypeString isEqualToString:@"0"]) {
                    firstCell.numberTextField.userInteractionEnabled = YES;
                    firstCell.snTextField.userInteractionEnabled = NO;
//                    firstCell.snTextField.placeholder = @"耗材不需要填写序列号";
                }else {
                    firstCell.numberTextField.userInteractionEnabled = YES;
                    firstCell.snTextField.userInteractionEnabled = YES;
                    firstCell.snTextField.placeholder = @"";

                }

                firstCell.arrowImageView.image =BDFILEIMAGENAEM(@"UserCenter/arrow.png");
                firstCell.arrowtwoImageView.image =BDFILEIMAGENAEM(@"UserCenter/arrow.png");
                firstCell.deleteButton.tag = section * 1000 + indexPath.row * 100;
                [firstCell.deleteButton setTitle:[UtilCheck language:@"order.delete"] forState:UIControlStateNormal];
                [firstCell.deleteButton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
                firstCell.messageLabel.text = [NSString stringWithFormat:@"%@(%ld)",[UtilCheck language:@"order.faultpart.info"],indexPath.row +1];
                // - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
                
                firstCell.nameTextField.tag = section * 1000 + indexPath.row * 100 + 1;
                firstCell.nameTextField.text = [dic objectForKey:@"name"];
                firstCell.nameTextField.placeholder = [UtilCheck language:@"order.choice.or.input"];
                
                
                firstCell.codeTextField.tag = section * 1000 + indexPath.row * 100 + 2;
                firstCell.codeTextField.text = [dic objectForKey:@"code"];
                firstCell.versionCodeTextField.tag = section * 1000 + indexPath.row * 100 + 3;
                firstCell.versionCodeTextField.text = [dic objectForKey:@"versionCode"];
//                firstCell.versionCodeTextField.userInteractionEnabled = NO;
                
                firstCell.snScanButton.tag = section * 1000 + indexPath.row * 100 + 13;
                
                [firstCell.snScanButton addTarget:self action:@selector(scanButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
                
                firstCell.snTextField.tag = section * 1000 + indexPath.row * 100 + 4;
                firstCell.snTextField.text = [dic objectForKey:@"sn"];
                firstCell.detailTextField.tag = section * 1000 + indexPath.row * 100 + 5;
                firstCell.detailTextField.text = [dic objectForKey:@"detail"];
//                firstCell.detailTextField.placeholder = [UtilCheck language:@"order.30.charcters.limit"];
                firstCell.stationNameTextField.tag = section * 1000 + indexPath.row * 100 + 6;
                firstCell.stationNameTextField.text = [dic objectForKey:@"stationName"];
                
                firstCell.isUseOneLineButton.tag = section * 1000 + indexPath.row * 100 + 7;
                firstCell.numberTextField.tag = section * 1000 + indexPath.row * 100 + 8;
                NSLog(@"数据＝＝＝＝＝＝%ld  == %@",indexPath.row,pieceArray[indexPath.row]);
                
                firstCell.numberTextField.text = [dic objectForKey:@"number"];
                firstCell.numberTextField.keyboardType = UIKeyboardTypePhonePad;

                [firstCell.isUseOneLineButton setTitle:[UtilCheck language:@"order.no"] forState:UIControlStateNormal];
                
                firstCell.arrowImageView.userInteractionEnabled=YES;
                UITapGestureRecognizer *Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
                [firstCell.nameTextField addGestureRecognizer:Recognizer];
                Recognizer.view.tag = 301 + indexPath.row;
                UITapGestureRecognizer *codeRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
                firstCell.codeTextField.userInteractionEnabled = YES;
                
                [firstCell.codeTextField addGestureRecognizer:codeRecognizer];
                codeRecognizer.view.tag = 301 + indexPath.row;
                
                firstCell.nameTextField.delegate = self;
                firstCell.codeTextField.delegate = self;
                firstCell.versionCodeTextField.delegate = self;
                firstCell.snTextField.delegate = self;
                firstCell.detailTextField.delegate = self;
                firstCell.stationNameTextField.delegate = self;
                firstCell.numberTextField.delegate = self;
                [firstCell.isUseOneLineButton addTarget:self action:@selector(isUseOneLine:) forControlEvents:UIControlEventTouchUpInside];
                
                firstCell.nameLabel.text = [UtilCheck language:@"order.faultpart.name"];
                firstCell.codeLabel.text = [UtilCheck language:@"order.faultpart.code"];
                firstCell.versionLabel.text = [UtilCheck language:@"order.faultpart.version"];
                firstCell.snLabel.text = [UtilCheck language:@"order.faultpart.sn"];
                firstCell.numberLabel.text = [UtilCheck language:@"order.quantity"];
                firstCell.describeLabel.text = [UtilCheck language:@"order.fault.describe"];
                firstCell.stationNameLabel.text = [UtilCheck language:@"order.station.name"];
                firstCell.oneLinepartLabel.text = [UtilCheck language:@"order.is.use.oneLinepart"];
                
                
                    if ([[pieceArray[indexPath.row] objectForKey:@"is_version"] isEqualToString:@"1"]) {
                        UILabel *versionLable = [[UILabel alloc]initWithFrame:CGRectMake(firstCell.versionLabel.right, firstCell.snLabel.origin.y-10, 15, 15)];
                        versionLable.textColor = [UIColor redColor];
                        versionLable.text = @"*";
                        [firstCell addSubview:versionLable];
                    }
                
                
                // 分割线设置
                for (int i = 0; i < 8; i++) {
                    RZCustomLable *lable = [[RZCustomLable alloc]init];
                    [lable setFrame:CGRectMake(0, 43.5 + 44 * i , tabelView.width, 0.5)];
                    [lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
                    [firstCell.myView addSubview:lable];
                }
                
                return firstCell;
                
            }else if ([[dic objectForKey:@"isUseOneLine"] isEqualToString:[UtilCheck language:@"order.yes"]]){
                CSNewOrderUseRepairsCell *repairesCell = [tabelView dequeueReusableCellWithIdentifier:@"CSNewOrderUseRepairsCell" forIndexPath:indexPath];
                repairesCell.selectionStyle = UITableViewCellSelectionStyleNone;
                if (self.dict != nil) {
                    repairesCell.numberTextField.userInteractionEnabled = NO;
                    repairesCell.deleteButton.hidden = YES;
                }else {
                    if (indexPath.row == 0) {
                        repairesCell.deleteButton.hidden = YES;
                    }else {
                        repairesCell.deleteButton.hidden = NO;
                    }
                }
                if ([[pieceArray[indexPath.row] objectForKey:@"faultPartType"] isEqualToString:@"0"]) {
                    repairesCell.numberTextField.userInteractionEnabled = YES;
                    repairesCell.snTextField.userInteractionEnabled = NO;
//                    repairesCell.snTextField.placeholder = @"耗材不需要填写序列号";
                }else {
                    repairesCell.numberTextField.userInteractionEnabled = NO;
                    repairesCell.snTextField.userInteractionEnabled = YES;
                    repairesCell.snTextField.placeholder = @"";
                    repairesCell.numberTextField.textColor = [UIColor lightGrayColor];
                }
                repairesCell.arrowImageViwe.image =BDFILEIMAGENAEM(@"UserCenter/arrow.png");
                repairesCell.arrowtowImageView.image =BDFILEIMAGENAEM(@"default/iconfont-jinru");
                if (indexPath.row == 0 || self.dict != nil) {
                    repairesCell.deleteButton.hidden = YES;
                }else {
                    repairesCell.deleteButton.hidden = NO;
                }
                repairesCell.deleteButton.tag = section * 1000 + indexPath.row * 100;
                [repairesCell.deleteButton setTitle:[UtilCheck language:@"order.delete"] forState:UIControlStateNormal];
                [repairesCell.deleteButton addTarget:self action:@selector(delete:) forControlEvents:UIControlEventTouchUpInside];
                repairesCell.messageLabel.text = [NSString stringWithFormat:@"%@(%ld)",[UtilCheck language:@"order.faultpart.info"],indexPath.row +1];
                repairesCell.arrowImageViwe.tag = section * 1000 + indexPath.row * 100 + 1;
                repairesCell.codeTextField.tag = section * 1000 + indexPath.row * 100 + 2;
                repairesCell.codeTextField.text = [dic objectForKey:@"code"];
                repairesCell.versionCodeTextField.tag = section * 1000 + indexPath.row * 100 + 3;
                repairesCell.versionCodeTextField.text = [dic objectForKey:@"versionCode"];
//                repairesCell.versionCodeTextField.userInteractionEnabled = NO;

                repairesCell.snTextField.tag = section * 1000 + indexPath.row * 100 + 4;
                repairesCell.snTextField.text = [dic objectForKey:@"sn"];
                repairesCell.detailTextField.tag = section * 1000 + indexPath.row * 100 + 5;
                repairesCell.detailTextField.text = [dic objectForKey:@"detail"];
//                repairesCell.detailTextField.placeholder = [UtilCheck language:@"order.30.charcters.limit"];
                repairesCell.stationNameTextField.tag = section * 1000 + indexPath.row * 100 + 6;
                repairesCell.stationNameTextField.text = [dic objectForKey:@"stationName"];
                repairesCell.isUseOneLineButton.tag = section * 1000 + indexPath.row * 100 + 7;
                [repairesCell.isUseOneLineButton setTitle:[UtilCheck language:@"order.yes"] forState:UIControlStateNormal];
                repairesCell.oneLineNameLabel.tag = section * 1000 + indexPath.row * 100 + 8;
                repairesCell.oneLineNameLabel.text = [dic objectForKey:@"oneLineName"];
                
                repairesCell.oneLineNameLabel.userInteractionEnabled=YES;
                UITapGestureRecognizer *oneLineRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
                [repairesCell.oneLineNameLabel addGestureRecognizer:oneLineRecognizer];
                oneLineRecognizer.view.tag = section * 1000 + indexPath.row * 100 + 8;
                
                repairesCell.oneLineCodeTextField.tag = section * 1000 + indexPath.row * 100 + 9;
                repairesCell.oneLineCodeTextField.text = [dic objectForKey:@"oneLineCode"];
                repairesCell.oneLineOneLineVersionTextField.tag = section * 1000 + indexPath.row * 100 + 10;
                repairesCell.oneLineOneLineVersionTextField.text = [dic objectForKey:@"oneLineOneLineVersion"];
                repairesCell.oneLineOneLineSNTextField.tag = section * 1000 + indexPath.row * 100 + 11;
                repairesCell.oneLineOneLineSNTextField.text = [dic objectForKey:@"oneLineOneLineSN"];
                repairesCell.nameTextField.tag = section * 1000 + indexPath.row * 100 + 12;
                repairesCell.nameTextField.text = [dic objectForKey:@"name"];
                repairesCell.nameTextField.placeholder = [UtilCheck language:@"order.choice.or.input"];
                
                repairesCell.numberTextField.tag = section * 1000 +indexPath.row * 100 + 13;
                repairesCell.numberTextField.text = [dic objectForKey:@"number"];
                repairesCell.numberTextField.delegate = self;
                repairesCell.numberTextField.keyboardType = UIKeyboardTypePhonePad;
                
                repairesCell.arrowImageViwe.userInteractionEnabled=YES;
                UITapGestureRecognizer *Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
                [repairesCell.nameTextField addGestureRecognizer:Recognizer];
                Recognizer.view.tag = 301 + indexPath.row;
                UITapGestureRecognizer *codeRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
                repairesCell.codeTextField.userInteractionEnabled = YES;
                
                [repairesCell.codeTextField addGestureRecognizer:codeRecognizer];
                codeRecognizer.view.tag = 201 + indexPath.row;
                
                repairesCell.nameTextField.delegate= self;
                repairesCell.codeTextField.delegate = self;
                repairesCell.versionCodeTextField.delegate = self;
                repairesCell.snTextField.delegate = self;
                repairesCell.detailTextField.delegate = self;
                repairesCell.stationNameTextField.delegate = self;
                repairesCell.oneLineNameTextField.delegate = self;
                repairesCell.oneLineCodeTextField.delegate = self;
                repairesCell.oneLineOneLineVersionTextField.delegate = self;
                repairesCell.oneLineOneLineSNTextField.delegate = self;
                [repairesCell.isUseOneLineButton addTarget:self action:@selector(isUseOneLine:) forControlEvents:UIControlEventTouchUpInside];
                
                repairesCell.nameLabel.text = [UtilCheck language:@"order.faultpart.name"];
                repairesCell.codeLabel.text = [UtilCheck language:@"order.faultpart.code"];
                repairesCell.versionLabel.text = [UtilCheck language:@"order.faultpart.version"];
                repairesCell.snLabel.text = [UtilCheck language:@"order.faultpart.sn"];
                repairesCell.numberLabel.text = [UtilCheck language:@"order.quantity"];
                repairesCell.describeLabel.text = [UtilCheck language:@"order.fault.describe"];
                repairesCell.stationNameLabel.text = [UtilCheck language:@"order.station.name"];
                repairesCell.oneLinepartLabel.text = [UtilCheck language:@"order.is.use.oneLinepart"];
                repairesCell.partNameLabel.text = [UtilCheck language:@"order.part.name"];
                repairesCell.partCodeLabel.text = [UtilCheck language:@"order.part.code"];
                repairesCell.partVersionLabel.text = [UtilCheck language:@"order.part.version"];
                repairesCell.partSNLabel.text = [UtilCheck language:@"order.part.sn"];
                
                
                    if ([[pieceArray[indexPath.row] objectForKey:@"is_version"] isEqualToString:@"1"]) {
                        UILabel *versionLable = [[UILabel alloc]initWithFrame:CGRectMake(repairesCell.versionLabel.right, repairesCell.snLabel.origin.y-10, 15, 15)];
                        versionLable.textColor = [UIColor redColor];
                        versionLable.text = @"*";
                        [repairesCell addSubview:versionLable];
                    }
                
                
                
                [repairesCell.partNameLabel sizeToFit];
                
                // 分割线设置
                for (int i = 0; i < 13; i++) {
                    RZCustomLable *lable = [[RZCustomLable alloc]init];
                    [lable setFrame:CGRectMake(0, 44 * i - 0.5, tabelView.width, 0.5)];
                    [lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
                    [repairesCell.myView addSubview:lable];
                }
                
                
                return repairesCell;
            }
            
        }else if (section == 2){
            
            CSNewOrderDeliveryCell *orderDelivery = [tableView dequeueReusableCellWithIdentifier:@"CSNewOrderDeliveryCell" forIndexPath:indexPath];
            orderDelivery.selectionStyle = UITableViewCellSelectionStyleNone;
            orderDelivery.takeTimeLabel.text  =  [UtilCheck language:@"CreatingOrders.FaultyUnitsAvailableTime"];
            orderDelivery.nameLabel.text = [UtilCheck language:@"order.take.at.same.time"];
            if (delivery == 0) {
                [orderDelivery.nayButton setImage:BDFILEIMAGENAEM(@"Order/img_radio_selected.png") forState:UIControlStateNormal];
                [orderDelivery.correctButton setImage:BDFILEIMAGENAEM(@"Order/img_radio.png") forState:UIControlStateNormal];
            }else if (delivery == 1){
                [orderDelivery.nayButton setImage:BDFILEIMAGENAEM(@"Order/img_radio.png") forState:UIControlStateNormal];
                [orderDelivery.correctButton setImage:BDFILEIMAGENAEM(@"Order/img_radio_selected.png") forState:UIControlStateNormal];
            }

            [orderDelivery.nayButton setTitle:[UtilCheck language:@"order.no"] forState:UIControlStateNormal];
            [orderDelivery.correctButton setTitle:[UtilCheck language:@"order.yes"] forState:UIControlStateNormal];
            [orderDelivery.nayButton addTarget:self action:@selector(negate) forControlEvents:UIControlEventTouchUpInside];
            [orderDelivery.correctButton addTarget:self action:@selector(orrect) forControlEvents:UIControlEventTouchUpInside];
            
            RZCustomLable *lable = [[RZCustomLable alloc]init];
            [lable setFrame:CGRectMake(0, 0, tabelView.width, 0.5)];
            [lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [orderDelivery addSubview:lable];
            RZCustomLable *linLable = [[RZCustomLable alloc]init];
            [linLable setFrame:CGRectMake(0, 43.5, tabelView.width, 0.5)];
            [linLable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [orderDelivery addSubview:linLable];
            RZCustomLable *lin2Lable = [[RZCustomLable alloc]init];
            [lin2Lable setFrame:CGRectMake(0, 87.5, tabelView.width, 0.5)];

            [orderDelivery addSubview:lin2Lable];

            if (delivery == 1) {
                [lin2Lable setBackgroundColor:[UIColor whiteColor]];
                orderDelivery.takeTimeLabel.hidden = YES;
                orderDelivery.timeInputLabel.hidden = YES;
            }else {
                [lin2Lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];

                orderDelivery.takeTimeLabel.hidden = NO;
                orderDelivery.timeInputLabel.hidden = NO;
                if (timeInput.length != 0) {
                    orderDelivery.timeInputLabel.text = timeInput;
                }

            }
            orderDelivery.timeInputLabel.userInteractionEnabled = YES;
            UITapGestureRecognizer *Recognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(acquireData:)];
            [orderDelivery.timeInputLabel addGestureRecognizer:Recognizer];
            Recognizer.view.tag = 401;
            
            
            return orderDelivery;
            
        }else if (section == 3){
            
            CSNewOrderMessageCell * ordercell = [tableView dequeueReusableCellWithIdentifier:@"CSNewOrderMessageCell" forIndexPath:indexPath];
            ordercell.selectionStyle = UITableViewCellSelectionStyleNone;
            ordercell.nameLabel.text = [UtilCheck language:@"order.remark"];
            ordercell.messageTextView.tag = section * 1000;
            ordercell.messageTextView.text = remark;
            ordercell.messageTextView.delegate = self;
            
            RZCustomLable *lable = [[RZCustomLable alloc]init];
            [lable setFrame:CGRectMake(0, 0, tabelView.width, 0.5)];
            [lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [ordercell addSubview:lable];
            RZCustomLable *linLable = [[RZCustomLable alloc]init];
            [linLable setFrame:CGRectMake(0, 59.5, tabelView.width, 0.5)];
            [linLable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [ordercell addSubview:linLable];
            return ordercell;
        }
        return nil;
    
}

- (void)orrect{
    delivery = 1;
    [tabelView reloadData];
}
- (void)negate{
    delivery = 0;
    [tabelView reloadData];
}
#pragma mark 表头
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        
        UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.bounds.size.width, 30)];
        headerView.backgroundColor = [UtilCheck hexStringToColor:@"f5f7fa" alpha:1];
        
        RZCustomLable *receiptInfo = [[RZCustomLable alloc]initWithFrame:CGRectMake(8, 5, 200, 20)];
        receiptInfo.text = [NSString stringWithFormat:@"%@",[UtilCheck language:@"order.receive.info"]];
        receiptInfo.textColor = [UtilCheck hexStringToColor:@"858e99" alpha:1];
        receiptInfo.font = [UIFont systemFontOfSize:11.5];
        [headerView addSubview:receiptInfo];
        
        RZCustomButtom *rightButton = [RZCustomButtom buttonWithType:UIButtonTypeCustom];
        [rightButton setTitle:[UtilCheck language:@"setting.addConsignee"] forState:UIControlStateNormal];
        [rightButton setTitleColor:[UtilCheck hexStringToColor:@"0056b8" alpha:1] forState:UIControlStateNormal];
        rightButton.frame = CGRectMake(headerView.bounds.size.width - 110, 0, 100, 30);
        rightButton.titleLabel.font = [UIFont systemFontOfSize:14.0];
        [rightButton addTarget:self action:@selector(RightButton) forControlEvents:UIControlEventTouchUpInside];
        [headerView addSubview:rightButton];
        
        return headerView;
    }else if (section == 2){
        if (self.dict != nil) {
            
        }else {
            UIView *header = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.bounds.size.width, 60)];
            header.backgroundColor = [UIColor whiteColor];

            RZCustomLable *lable = [[RZCustomLable alloc]init];
            [lable setFrame:CGRectMake(0, 0 , tabelView.width, 0.5)];
            [lable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [header addSubview:lable];
            RZCustomLable *linLable = [[RZCustomLable alloc]init];
            [linLable setFrame:CGRectMake(0, header.height - 10.5, tabelView.width, 0.5)];
            [linLable setBackgroundColor:[UtilCheck hexStringToColor:@"e1e1df" alpha:1]];
            [header addSubview:linLable];
            
            RZCustomButtom *append = [[RZCustomButtom alloc]init];
            append.frame = CGRectMake((tabelView.bounds.size.width - 150) / 2,10,150,30);
            [append setImage:BDFILEIMAGENAEM(@"Order/btn_add.png") forState:UIControlStateNormal];
            append.titleLabel.font = [UIFont systemFontOfSize:14];
            [append setTitle:[NSString stringWithFormat:@"  %@",[UtilCheck language:@"order.add.faultpart.info"]] forState:UIControlStateNormal];
            [append setTitleColor:[UtilCheck hexStringToColor:@"6990f3" alpha:1] forState:UIControlStateNormal];
            [append addTarget:self action:@selector(additionMessage) forControlEvents:UIControlEventTouchUpInside];
            [header addSubview:append];

            RZCustomButtom *sweepButton = [[RZCustomButtom alloc]initWithFrame:CGRectMake(header.bounds.size.width - 55, 10, 40, 40)];
            sweepButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentCenter;
            [sweepButton setImage:BDFILEIMAGENAEM(@"Order/scan.png") forState:UIControlStateNormal];
            sweepButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 10, 0);
            sweepButton.titleLabel.font = [UIFont systemFontOfSize:10];
             [sweepButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
            sweepButton.titleEdgeInsets = UIEdgeInsetsMake(30, -20, 0, 0);
            [sweepButton addTarget:self action:@selector(sweepButton) forControlEvents:UIControlEventTouchUpInside];
            
            [header addSubview:sweepButton];
            
            RZCustomLable *backgroundLabel = [[RZCustomLable alloc]initWithFrame:CGRectMake(0, 50, header.bounds.size.width, 10)];
            backgroundLabel.backgroundColor = [UtilCheck hexStringToColor:@"f5f7fa" alpha:1];
            [header addSubview:backgroundLabel];

            return header;
        }
        
    }
    
    return nil;
}


/**
 板件序列号扫描事件

 @param sender 板件序列号按钮
 */
- (void)scanButtonAction:(UIButton *)sender {
    
    NSInteger index = (sender.tag % 1000) / 100;
    
    MHScanViewController *MHsvc = [[MHScanViewController alloc]init];
    MHsvc.isdismiss = YES;
    
    MHsvc.rebackData = ^(NSString *retStr){
        
        NSMutableDictionary *params = [NSMutableDictionary dictionary];
        params[@"code"] = retStr;
        params[@"orderType"] = @"1";
        
        [[BDHUD sharedManager] showBDHUD:self.view title:nil];
        [AFHttpTool postJsonDatawithUrl:@"scanAddFailureparts" parameters:[params mutableCopy] success:^(id responseObject) {
            [[BDHUD sharedManager] dismissHUD];
            
            NSArray *arr = responseObject[@"data"];
            if (arr.count != 0) {

                NSDictionary *dic = arr[0];
                NSLog(@"二维码获取的数据 %@",dic);
                NSMutableDictionary *dictionary = pieceArray[index];
                
                if (![Toolobject IsEmptyString:dic[@"name"]]) {
                    [dictionary setObject:dic[@"name"] forKey:@"name"];
                }
                if (![Toolobject IsEmptyString:dic[@"code"]]) {
                    [dictionary setObject:dic[@"code"] forKey:@"code"];
                }
                if (![Toolobject IsEmptyString:dic[@"version"]]) {
                    [dictionary setObject:dic[@"version"] forKey:@"versionCode"];
                }
                if (![Toolobject IsEmptyString:dic[@"sn"]]) {
                    [dictionary setObject:dic[@"sn"] forKey:@"sn"];
                }
                else {
                    [dictionary setObject:retStr forKey:@"sn"];
                }
                
                [dictionary setObject:@"1" forKey:@"number"];
                [dictionary setObject:[UtilCheck language:@"order.no"] forKey:@"stationName"];
                
                if (![Toolobject IsEmptyString:@"faultPartType"]) {
                    [dictionary setObject:[NSString stringWithFormat:@"%@",dic[@"faultPartType"]] forKey:@"faultPartType"];
                }
                
                [pieceArray replaceObjectAtIndex:index withObject:dictionary];
                [tabelView reloadData];
                
            }
            else {
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.did.not.find.the.related.plate"]];
            }
            
        } fail:^(id responseObject, NSError *error) {
            [[BDHUD sharedManager] dismissHUD];
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.title.the.data.load.failure"]];
        }];
    };
    
    CustomNavigationController *vc = [[CustomNavigationController alloc]initWithRootViewController:MHsvc];
    [self presentViewController:vc animated:YES completion:^{
        
    }];
    
}


- (void)sweepButton {
    
    MHScanViewController *MHsvc = [[MHScanViewController alloc]init];
    MHsvc.isdismiss = YES;

    MHsvc.rebackData = ^(NSString *retStr){
        
        NSMutableDictionary *params = [NSMutableDictionary dictionary];

        params[@"code"] = retStr;
        
        params[@"orderType"] = @"1";
        
        [[BDHUD sharedManager] showBDHUD:self.view title:nil];
        [AFHttpTool postJsonDatawithUrl:@"scanAddFailureparts" parameters:[params mutableCopy] success:^(id responseObject) {
            [[BDHUD sharedManager] dismissHUD];
            
                NSArray *arr = responseObject[@"data"];
                if (arr.count != 0) {
                    NSDictionary *dic = arr[0];
                    
                    NSLog(@"二维码获取的数据 %@",dic);
                    
                    if (arr.count == 1) {
                        NSMutableDictionary *DataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"rma",@"",@"id",dic[@"name"],@"name",dic[@"code"],@"code",dic[@"version"],@"versionCode",dic[@"sn"],@"sn",@"1",@"number",@"",@"detail",@"",@"stationName",@"",@"siteID",[UtilCheck language:@"order.no"],@"isUseOneLine",[NSString stringWithFormat:@"%@",dic[@"faultPartType"]],@"faultPartType", nil];
                        NSLog(@"故障件数据%@",DataDic);
                        
                        [pieceArray addObject:DataDic];
                        
                    }else {
                        NSMutableDictionary *DataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"rma",@"",@"id",dic[@"name"],@"name",dic[@"code"],@"code",@"",@"versionCode",dic[@"sn"],@"sn",@"1",@"number",@"",@"detail",@"",@"stationName",@"",@"siteID",[UtilCheck language:@"order.no"],@"isUseOneLine",[NSString stringWithFormat:@"%@",dic[@"faultPartType"]],@"faultPartType", nil];
                        NSLog(@"故障件数据%@",DataDic);
                        
                        [pieceArray addObject:DataDic];
                        
                    }

                    [tabelView reloadData];
                }else {
                    [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.did.not.find.the.related.plate"]];
                }
            
        } fail:^(id responseObject, NSError *error) {
            [[BDHUD sharedManager] dismissHUD];
            
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"HUD.title.the.data.load.failure"]];
        }];
        
    };
    
    CustomNavigationController *vc = [[CustomNavigationController alloc]initWithRootViewController:MHsvc];
    
    [self presentViewController:vc animated:YES completion:^{
        
    }];
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 30;
    }else if (section == 1){
        return 0.01;
    }else if (section == 2){
        if (self.dict != nil) {
            return 0.01;
        }else {
            return 60;
        }
    }else if (section == 3){
        return 10;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.01;
}

// 点击获取收货信息数据
#pragma mark 获取数据
- (void)acquireData:(UITapGestureRecognizer *)tgr
{
    NSLog(@"点击的tag== %ld",tgr.view.tag);
    
        if (tgr.view.tag == 101) {   // 选择收货地址
            [[BDHUD sharedManager] showBDHUD:self.view title:nil];

            [AFHttpTool postJsonDatawithUrl:@"getAddresses" parameters:nil success:^(id responseObject) {
                [[BDHUD sharedManager] dismissHUD];

                if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
                    NSArray *array = [responseObject objectForKey:@"data"];
                    NSLog(@"地址为%@",array);
                    
                    NSMutableArray *actionArray = [[NSMutableArray alloc]init];
                    for (int i = 0; i < array.count; i++) {
                        [actionArray addObject:array[i][@"address"]];
                    }
                    PXAlertView *AlertView = [[PXAlertView alloc]initAlertWithTitle:[UtilCheck language:@"order.receive.address"] message:nil cancelTitle:nil otherTitle:nil contentView:nil completion:nil tableview:actionArray];
                    AlertView.delegate = self;
                    AlertView.mark = tgr.view.tag;
                    [AlertView show];
                }else {
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                
            } fail:^(id responseObject, NSError *error) {
                
                [[BDHUD sharedManager] dismissHUD];
                
                if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
                }else {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
                }
            }];
            
        }else if (tgr.view.tag == 104 || tgr.view.tag == 105 || tgr.view.tag == 103){    //选择时间
            UIView *maskView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.bounds.size.width, self.view.height*2)];
            maskView.backgroundColor = [UIColor whiteColor];
            maskView.alpha = 0.2f;
            self.maskView = maskView;
            [tabelView addSubview:self.maskView];
            //设置选择时间的TextField
            datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 216, self.view.frame.size.width, 216)];
            datePicker.backgroundColor = [UIColor whiteColor];
            
            datePicker.datePickerMode = UIDatePickerModeDateAndTime;
            datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:[UtilCheck language:@"datePicker.LocalID"]];
            //            datePicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];
            
            toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 216 - 44, self.view.frame.size.width, 44.0f)];
            toolBar.backgroundColor = [UIColor grayColor];
            UIBarButtonItem* leftItem = [[UIBarButtonItem alloc] initWithTitle:[UtilCheck language:@"button.cancel"] style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction)];
            UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
            UIBarButtonItem* rightItem = [[UIBarButtonItem alloc] initWithTitle:[UtilCheck language:@"button.done"] style:UIBarButtonItemStyleDone target:self action:@selector(confirmAction:)];
            rightItem.tag = tgr.view.tag;
            [toolBar setItems:@[leftItem,flexSpace,rightItem]];
            [self.view addSubview:datePicker];
            [self.view addSubview:toolBar];
            
        }else if (tgr.view.tag == 102){
            [[BDHUD sharedManager] showBDHUD:self.view title:nil];

            [AFHttpTool postJsonDatawithUrl:@"myConsignees" parameters:nil success:^(id responseObject) {
                [[BDHUD sharedManager] dismissHUD];

                if ([[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue] == 1) {
                    myConsigneesArray = [responseObject objectForKey:@"data"];
                    NSLog(@"地址为%@",myConsigneesArray);
                    
                    NSMutableArray *actionArray = [[NSMutableArray alloc]init];
                    for (NSDictionary *dic in myConsigneesArray) {
                        [actionArray addObject:[NSString stringWithFormat:@"%@ %@",dic[@"username"],dic[@"tel"]]];
                    }
                    PXAlertView *AlertView = [[PXAlertView alloc]initAlertWithTitle:[UtilCheck language:@"order.receiver.contacts"] message:nil cancelTitle:nil otherTitle:nil contentView:nil completion:nil tableview:actionArray];
                    AlertView.delegate = self;
                    AlertView.mark = tgr.view.tag;
                    [AlertView show];
                }else {
                    [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
                }
                
            } fail:^(id responseObject, NSError *error) {
                
                [[BDHUD sharedManager] dismissHUD];
                
                if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
                }else {
                    [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
                }
            }];
            
            
        }else if (tgr.view.tag / 100 == 3){
            CNewOrderFaultyPartsVC *vc = [[CNewOrderFaultyPartsVC alloc]init];
            vc.tag = [NSString stringWithFormat:@"%ld",tgr.view.tag];
            vc.judge = PartDefault;
            vc.orderType = @"1";
            if (self.dict != nil) {
                
                vc.fualtPartType = pieceArray[tgr.view.tag % 100 - 1][@"faultPartType"];
            }
            [self.navigationController pushViewController:vc animated:YES];
        }
    // 获取一线备件故障名
    if (tgr.view.tag % 10 == 8 && tgr.view.tag > 1000) {
        CNewOrderFaultyPartsVC *vc = [[CNewOrderFaultyPartsVC alloc]init];
        vc.tag = [NSString stringWithFormat:@"%ld",tgr.view.tag];
        vc.selectedIndex = 0;
        vc.judge = PartOneline;
        vc.code = pieceArray[tgr.view.tag / 100 - 10][@"code"];
        vc.number = pieceArray[tgr.view.tag / 100 - 10][@"number"];
        NSString *existOneLineIDs = @"";
        for (int i = 0 ; i<pieceArray.count ; i++) {
            NSMutableDictionary *tempDict = [[NSMutableDictionary alloc]initWithDictionary:pieceArray[i]];
            
            if ( ![ Toolobject IsEmptyString:[tempDict objectForKey:@"oneLineID"]] ) {
                existOneLineIDs = [NSString stringWithFormat:@"%@'%@',",existOneLineIDs,[tempDict objectForKey:@"oneLineID"]];
            }

        }
        if ([existOneLineIDs length] >= 1) {
            existOneLineIDs = [existOneLineIDs substringWithRange:NSMakeRange(0, [existOneLineIDs length] - 1)];
        }
        vc.existOneLineIDs =existOneLineIDs ;
        
        [self.navigationController pushViewController:vc animated:YES];
    }
    if (tgr.view.tag == 401) {
        UIView *maskView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, tabelView.bounds.size.width, self.view.height*2)];
        maskView.backgroundColor = [UIColor whiteColor];
        maskView.alpha = 0.2f;
        self.maskView = maskView;
        [tabelView addSubview:self.maskView];
        //设置选择时间的TextField
        datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 216, self.view.frame.size.width, 216)];
        datePicker.backgroundColor = [UIColor whiteColor];
        
        datePicker.datePickerMode = UIDatePickerModeDateAndTime;
        datePicker.locale = [[NSLocale alloc] initWithLocaleIdentifier:[UtilCheck language:@"datePicker.LocalID"]];
        //            datePicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];
        
        toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 216 - 44, self.view.frame.size.width, 44.0f)];
        toolBar.backgroundColor = [UIColor grayColor];
        UIBarButtonItem* leftItem = [[UIBarButtonItem alloc] initWithTitle:[UtilCheck language:@"button.cancel"] style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction)];
        UIBarButtonItem *flexSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
        UIBarButtonItem* rightItem = [[UIBarButtonItem alloc] initWithTitle:[UtilCheck language:@"button.done"] style:UIBarButtonItemStyleDone target:self action:@selector(confirmAction:)];
        rightItem.tag = tgr.view.tag;
        [toolBar setItems:@[leftItem,flexSpace,rightItem]];
        [self.view addSubview:datePicker];
        [self.view addSubview:toolBar];
    }
    
}

-(void) cancelAction {
    [self.maskView removeFromSuperview];
    [datePicker removeFromSuperview];
    [toolBar removeFromSuperview];
    
}

-(void) confirmAction:(UIBarButtonItem *)item {
    [self.maskView removeFromSuperview];
    [datePicker removeFromSuperview];
    [toolBar removeFromSuperview];
    
    if (item.tag == 104 || item.tag == 105 || item.tag == 103) {
        NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyy-MM-dd HH:mm";
        
        //选择时间不能大于当前时间
        NSDate *selectedDate = datePicker.date;
        NSDate *nowDate = [NSDate date];
        
        if ([selectedDate earlierDate:nowDate] == selectedDate ) {
            [Toolobject showTextWithMessage:[UtilCheck language:@"datePicker.noBeforeNow"]];
            return;
        }
        NSString *dateStr = [formatter stringFromDate:datePicker.date];
        if (item.tag == 104) {
            [dataDic setValue:dateStr forKey:@"time"];
        }else if(item.tag == 105){
            [dataDic setValue:dateStr forKey:@"service_time"];
        }else {
            [dataDic setValue:dateStr forKey:@"customerOrderTime"];
        }
        [tabelView reloadData];
        
    }else if (item.tag == 401){
        NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
        formatter.dateFormat = @"yyyy-MM-dd HH:mm";
        
        //选择时间不能大于当前时间
        NSDate *selectedDate = datePicker.date;
        NSDate *nowDate = [NSDate date];
        
        if ([selectedDate earlierDate:nowDate] == selectedDate ) {
            [Toolobject showTextWithMessage:[UtilCheck language:@"datePicker.noBeforeNow"]];
            return;
        }
        NSString *dateStr = [formatter stringFromDate:datePicker.date];
        timeInput = [NSString  stringWithFormat:@"%@",dateStr];
        [tabelView reloadData];
    }
}

#pragma mark PXAlertViewDelegate 选择获取的数据放入label中
- (void)getselect:(NSString *)getselect mark:(int)mark row:(int)row
{
    NSLog(@"%@    %d     %d",getselect,mark,row);

    
    
    
    
        if (getselect != nil) {
            if (mark == 101) {
                [dataDic setValue:getselect forKey:@"address"];
                
                [tabelView reloadData];
            }else if (mark == 104 || mark == 105 || mark == 103){
            }else if (mark == 102){
                [dataDic setValue:getselect forKey:@"tel"];
                [dataDic setValue:myConsigneesArray[row][@"id"] forKey:@"user"];
                [tabelView reloadData];
            }
        }
    
}


#pragma mark 删除故障件信息
- (void)delete:(UIButton *)button
{
    
    NSLog(@"%ld",button.tag);
    
        NSInteger teg = button.tag / 100 - 10;
        
        [pieceArray removeObjectAtIndex:teg];
        
        [tabelView reloadData];
}
#pragma mark 保存textField数据
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    NSLog(@"点击的TAg＝＝ %ld  ＝＝＝ %@",(long)textField.tag,[pieceArray[textField.tag / 100 - 10] objectForKey:@"isUseOneLine"]);

            if ([[pieceArray[textField.tag / 100 - 10] objectForKey:@"isUseOneLine"] isEqualToString:[UtilCheck language:@"order.no"]]) {
                
                
                if (textField.tag % 100 == 1) {
                    pieceArray[textField.tag / 100 - 10][@"name"] = textField.text;
                    
                }else if (textField.tag % 100 == 2){
                    pieceArray[textField.tag / 100 - 10][@"code"] = textField.text;
                    
                }else if (textField.tag % 100 == 3){
                    pieceArray[textField.tag / 100 - 10][@"versionCode"] = textField.text;
                    
                }else if (textField.tag % 100 == 4){
                    pieceArray[textField.tag / 100 - 10][@"sn"] = textField.text;
                    NSString *snString = pieceArray[textField.tag / 100 - 10][@"sn"];
                    if (snString.length > 0) {
                        pieceArray[textField.tag / 100 - 10][@"number"] = @"1";
                    }
                    
                }else if (textField.tag % 100 == 5){
                    pieceArray[textField.tag / 100 - 10][@"detail"] = textField.text;
                    
                }else if (textField.tag % 100 == 6){
                    pieceArray[textField.tag / 100 - 10][@"stationName"] = textField.text;
                    
                }else if (textField.tag % 100 == 7){
                    pieceArray[textField.tag / 100 - 10][@"isUseOneLine"] = textField.text;
                }else if (textField.tag % 100 == 8){
                    
                        pieceArray[textField.tag / 100 - 10][@"number"] = textField.text;
                        if ([textField.text intValue] > 1){
                            pieceArray[textField.tag / 100 - 10][@"sn"] = @"";
                        }
                }

            }else if ([[pieceArray[textField.tag / 100 - 10] objectForKey:@"isUseOneLine"] isEqualToString:[UtilCheck language:@"order.yes"]]){
                
                
                if (textField.tag % 100 == 12) {
                    pieceArray[textField.tag / 100 - 10][@"name"] = textField.text;
                    
                }else if (textField.tag % 100 == 2){
                    pieceArray[textField.tag / 100 - 10][@"code"] = textField.text;
                    
                }else if (textField.tag % 100 == 3){
                    pieceArray[textField.tag / 100 - 10][@"versionCode"] = textField.text;
                    
                }else if (textField.tag % 100 == 4){
                    pieceArray[textField.tag / 100 - 10][@"sn"] = textField.text;
                    NSString *snString = pieceArray[textField.tag / 100 % 10][@"sn"];
                    if (snString.length > 0) {
                        pieceArray[textField.tag / 100 - 10][@"number"] = @"1";
                    }
                }else if (textField.tag % 100 == 5){
                    pieceArray[textField.tag / 100 - 10][@"detail"] = textField.text;
                    
                }else if (textField.tag % 100 == 6){
                    pieceArray[textField.tag / 100 - 10][@"stationName"] = textField.text;
                    
                }else if (textField.tag % 100 == 7){
                    pieceArray[textField.tag / 100 - 10][@"isUseOneLine"] = textField.text;
                    
                }else if (textField.tag % 100 == 8){
                    pieceArray[textField.tag / 100 - 10][@"oneLineName"] = textField.text;
                    
                }else if (textField.tag % 100 == 9){
                    pieceArray[textField.tag / 100 - 10][@"oneLineCode"] = textField.text;
                    
                }else if (textField.tag % 100 == 10){
                    pieceArray[textField.tag / 100 - 10][@"oneLineOneLineVersion"] = textField.text;
                    
                }else if (textField.tag % 100 == 11){
                    pieceArray[textField.tag / 100 - 10][@"oneLineOneLineSN"] = textField.text;
                    
                }else if (textField.tag % 100 == 13){
                    pieceArray[textField.tag / 100 - 10][@"number"] = textField.text;
                    if ([textField.text intValue] > 1){
                        pieceArray[textField.tag / 100 - 10][@"sn"] = @"";
                    }
                }
                
            }
    
    [tabelView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];

    return YES;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    [tabelView reloadData];

    return YES;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{

    [tabelView reloadData];

}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    NSMutableString *textString = [textView.text mutableCopy];
    [textString replaceCharactersInRange:range withString:text];
    NSInteger limitedLength = 200;
    
    if ([textString length] <= limitedLength || [textString isEqualToString:@""]) {
        return YES;
    }else {
        [Toolobject showAlterwithMessage:[NSString stringWithFormat:@"最多%ld个字符",(long)limitedLength]];
        return NO;
    }
    return YES;
}

- (void)textViewDidEndEditing:(UITextView *)textView{

        remark = textView.text;
        NSLog(@"备注%@",remark);
   
}
#pragma mark 点击是否使用一线备件
- (void)isUseOneLine:(UIButton *)button{
    
    NSString *string = pieceArray[button.tag / 100 - 10][@"code"];
    if (string.length != 0) {
        if ([[pieceArray[button.tag / 100 - 10] objectForKey:@"faultPartType"] isEqualToString:@"1"]) {
            NSLog(@"tag==%ld",(long)button.tag);
            NSLog(@"%@",pieceArray[button.tag / 100 - 10][@"number"]);
            
            if ([pieceArray[button.tag / 100 - 10][@"number"] isEqualToString:@"1"]) {
                alertView = [UIAlertController alertControllerWithTitle:[UtilCheck language:@"order.is.use.oneLinepart"] message:nil preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *rightAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"order.yes"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    NSLog(@"是");
                    
                    [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@"oneLineName"];
                    [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@"oneLineCode"];
                    [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@"oneLineOneLineVersion"];
                    [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@"oneLineOneLineSN"];
                    [pieceArray[button.tag / 100 - 10] setValue:[UtilCheck language:@"order.yes"] forKey:@"isUseOneLine"];
                    
                    [tabelView reloadData];
                }];
                UIAlertAction *denyAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"order.no"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    NSLog(@"否");
                    
                    [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@""];
                    [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@""];
                    [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@""];
                    [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@""];
                    [pieceArray[button.tag / 100 - 10] setValue:[UtilCheck language:@"order.no"] forKey:@"isUseOneLine"];
                    
                    [tabelView reloadData];
                }];
                
                [alertView addAction:rightAction];
                [alertView addAction:denyAction];
                [self presentViewController:alertView animated:YES completion:nil];
            }else {
                [[BDHUD sharedManager] showWords:[NSString stringWithFormat:@"%@",[THMangerTool language:@"order.faulty units qty must one"]]];
                
            }
            
        }else if ([[pieceArray[button.tag / 100 - 10] objectForKey:@"faultPartType"] isEqualToString:@"0"]) {
            alertView = [UIAlertController alertControllerWithTitle:[UtilCheck language:@"order.is.use.oneLinepart"] message:nil preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *rightAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"order.yes"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"是");
                
                [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@"oneLineName"];
                [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@"oneLineCode"];
                [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@"oneLineOneLineVersion"];
                [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@"oneLineOneLineSN"];
                [pieceArray[button.tag / 100 - 10] setValue:[UtilCheck language:@"order.yes"] forKey:@"isUseOneLine"];
                
                [tabelView reloadData];
            }];
            UIAlertAction *denyAction = [UIAlertAction actionWithTitle:[UtilCheck language:@"order.no"] style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                NSLog(@"否");
                
                [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@""];
                [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@""];
                [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@""];
                [pieceArray[button.tag / 100 - 10] setValue:@"" forKey:@""];
                [pieceArray[button.tag / 100 - 10] setValue:[UtilCheck language:@"order.no"] forKey:@"isUseOneLine"];
                
                [tabelView reloadData];
            }];
            
            [alertView addAction:rightAction];
            [alertView addAction:denyAction];
            [self presentViewController:alertView animated:YES completion:nil];

        }
    
    }else {
        [[BDHUD sharedManager] showWords:[THMangerTool language:@"customer.chooseFaultPlate"]];
    }
    
}

#pragma mark 限制字数
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
    NSMutableString *text = [textField.text mutableCopy];
    [text replaceCharactersInRange:range withString:string];
    NSInteger limitedLength = 50;
    
    if ([text length] <= limitedLength || [string isEqualToString:@""]) {
        return YES;
    }else {
        [Toolobject showAlterwithMessage:[NSString stringWithFormat:@"最多%ld个字符",(long)limitedLength]];
        return NO;
    }
    return YES;
}


#pragma mark 添加故障需求信息
- (void)additionMessage
{
    NSMutableDictionary *DataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"",@"rma",@"",@"id",@"",@"name",@"",@"code",@"",@"versionCode",@"",@"sn",@"1",@"number",@"",@"detail",@"",@"stationName",@"",@"siteID",[UtilCheck language:@"order.no"],@"isUseOneLine", nil];
    [pieceArray addObject:DataDic];
    
    [tabelView reloadData];
    
}
#pragma mark-提交订单
- (void)commitGoto{
        
        [self insertPartsManager];
    
}
#pragma mark 备件替换服务数据提交
- (void)insertPartsManager {
    
    NSLog(@"第一个信息%@",dataDic);
    NSLog(@"第二个信息%@",pieceArray);
    
    NSLog(@"第三个信息%ld",delivery);
    NSLog(@"第四个信息%@",remark);
    
    
    if ([UtilCheck DataIsNuLL:[dataDic objectForKey:@"address"]]) {
        [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.receive.address empty"]];
        return;
    }else if ([UtilCheck DataIsNuLL:[dataDic objectForKey:@"tel"]]) {
        [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.receiver.contacts empty"]];
        return;
    }
    for (int i = 0; i < pieceArray.count; i++) {
        
        if ([UtilCheck DataIsNuLL:[pieceArray[i] objectForKey:@"name"]]) {
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.faultpart.name empty"]];
            return;
        }else if ([UtilCheck DataIsNuLL:[pieceArray[i] objectForKey:@"code"]]) {
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.faultpart.code empty"]];
            return;
        }else if ([UtilCheck DataIsNuLL:[pieceArray[i] objectForKey:@"number"]]) {
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.faultpart.quantity Can't be empty"]];
            return;
        }else if([[pieceArray[i] objectForKey:@"is_version"] isEqualToString:@"1"] && [UtilCheck DataIsNuLL:[pieceArray[i] objectForKey:@"versionCode"]]) {
            [[BDHUD sharedManager] showWords:[THMangerTool language:@"order.faultpart.is_version empty"]];
            return;
        }
        NSString *height = [pieceArray[i] objectForKey:@"isUseOneLine"];
        
        if ([height isEqualToString:[UtilCheck language:@"order.yes"]]) {
            if ([UtilCheck DataIsNuLL:[pieceArray[i] objectForKey:@"oneLineName"]]) {
                [[BDHUD sharedManager] showWords:[THMangerTool language:@"Order.OnSiteSpareQty empty"]];
                return;
            }
        }
    }
 
    
    // 背景色
    shadowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    shadowView.backgroundColor = [UtilCheck hexStringToColor:@"a5a9aa" alpha:0.7];
    
    //    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(shadow)];
    //
    //    [shadowView addGestureRecognizer:tapGesture];
    
#pragma mark 故障件信息
    NSMutableDictionary *messageDic;
    messageDic = [[NSMutableDictionary alloc]init];
    for (int i = 0; i < pieceArray.count; i++) {
        int number;
        number = 1;
        NSString *name = pieceArray[i][@"name"];
        NSString *code = pieceArray[i][@"code"];
//        if (i >= 1) {
            number = 0;
            for (NSDictionary *dict in pieceArray) {
                
                if ([name isEqualToString:dict[@"name"]] && [code isEqualToString:dict[@"code"]]) {
                    number = number + [dict[@"number"] intValue];
                }
                [messageDic setObject:[NSString stringWithFormat:@"%d",number] forKey:[NSString stringWithFormat:@"%@  %@",name,code]];
//            }
        }
        
        [messageDic setObject:[NSString stringWithFormat:@"%d",number] forKey:[NSString stringWithFormat:@"%@  %@",name,code]];
    }
    NSLog(@"%@",messageDic);
#pragma mark 一线备件信息
    NSMutableDictionary *lineDic;
    lineDic = [[NSMutableDictionary alloc]init];
    for (int i = 0; i < pieceArray.count; i++) {
        if ([pieceArray[i][@"isUseOneLine"] isEqualToString:[UtilCheck language:@"order.yes"]]) {
            NSLog(@"      %@",pieceArray[i][@"oneLineInfo"]);
            
            int number;
            number = 1;
            NSString *name = pieceArray[i][@"oneLineName"];
            NSString *code = pieceArray[i][@"oneLineCode"];
            NSLog(@"一线备件的:%@ %@",name,code);
            
            if (i >= 1) {
                number = 0;
                for (NSDictionary *dict in pieceArray) {
                    
                    if ([name isEqualToString:dict[@"oneLineName"]] && [code isEqualToString:dict[@"oneLineCode"]]) {
                        number ++;
                    }
                    [lineDic setObject:[NSString stringWithFormat:@"%d",number] forKey:[NSString stringWithFormat:@"%@  %@",name,code]];
                    NSLog(@"%d",number);
                }
            }
            
            [lineDic setObject:[NSString stringWithFormat:@"%d",number] forKey:[NSString stringWithFormat:@"%@  %@",name,code]];
        }
        
    }
    NSLog(@"%@",lineDic);
    
    // 确认提交界面
    [self.view addSubview:shadowView];
    
    UIView *submitView;
    NSLog(@"%ld",messageDic.count + lineDic.count);
    
    if (messageDic.count + lineDic.count > 6) {
        
        submitView = [[UIView alloc]initWithFrame:CGRectMake(50, 70, self.view.bounds.size.width - 100, 70 + 40 + 100 + 55)];
        
    }else{
        
        
        if (lineDic.count >= 1) {
            submitView = [[UIView alloc]initWithFrame:CGRectMake(50, 70, self.view.bounds.size.width - 100, 70 + 40 + messageDic.count * 20 + 30 + 80 + 20 * lineDic.count)];
        }else {
            submitView = [[UIView alloc]initWithFrame:CGRectMake(50, 70, self.view.bounds.size.width - 100, 70 + 40 + messageDic.count * 20 + 55)];
        }
    }
    submitView.layer.cornerRadius = 5;
    submitView.layer.masksToBounds = YES;
    submitView.backgroundColor = [UtilCheck hexStringToColor:@"eaebec" alpha:1];;
    [shadowView addSubview:submitView];
    
    //头部
    UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, submitView.bounds.size.width, 70)];
    headView.backgroundColor = [UtilCheck hexStringToColor:@"9ed4e2" alpha:1];
    [submitView addSubview:headView];
    UIImageView *headImageView = [[UIImageView alloc]initWithFrame:CGRectMake((headView.bounds.size.width - 60) / 2, 5, 60, 60)];
    headImageView.image = BDFILEIMAGENAEM(@"Order/img_pack.png");
    [headView addSubview:headImageView];
    
#pragma mark 不可滚动
    
    NSLog(@"数据个数%ld",messageDic.count + lineDic.count);
    
    if (messageDic.count + lineDic.count <= 6) {
        UIView *defectiveView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, submitView.bounds.size.width, messageDic.count * 20 + 55)];
        defectiveView.backgroundColor = [UIColor whiteColor];
        [submitView addSubview:defectiveView];
        
        UILabel *defectiveLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 20)];
        defectiveLabel.text = [UtilCheck language:@"Order.OrderSummary"];
        defectiveLabel.font = [UIFont systemFontOfSize:15];
        [defectiveView addSubview:defectiveLabel];
        
        int j = 0;
        for (NSString *string in messageDic) {
            
            UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
            messageLabel.font = [UIFont systemFontOfSize:13];
            messageLabel.text = [NSString stringWithFormat:@"%@",string];
            [defectiveView addSubview:messageLabel];
            
            UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
            numberLabel.font = [UIFont systemFontOfSize:13];
            numberLabel.text = [NSString stringWithFormat:@"%@",messageDic[string]];
            [defectiveView addSubview:numberLabel];
            j++;
            
        }
        NSInteger  messageTotal = 0;
        for (NSString *string in messageDic) {
            messageTotal = messageTotal + [messageDic[string] intValue];
        }
        
        UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
        messageLabel.font = [UIFont systemFontOfSize:13];
        messageLabel.text = [THMangerTool language:@"show.totalCount"];
        messageLabel.backgroundColor = [UIColor whiteColor];
        [defectiveView addSubview:messageLabel];
        
        UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
        numberLabel.font = [UIFont systemFontOfSize:13];
        numberLabel.text = [NSString stringWithFormat:@"%ld",messageTotal];
        [defectiveView addSubview:numberLabel];
        j++;
        
        NSLog(@"%ld   %@",lineDic.count,lineDic);
        
        if (lineDic.count >= 1){
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0,71 + defectiveView.bounds.size.height, submitView.bounds.size.width, lineDic.count * 20 + 55)];
            lineView.backgroundColor = [UIColor whiteColor];
            [submitView addSubview:lineView];
            
            UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 20)];
            lineLabel.text = [THMangerTool language:@"newOrder.UseOnSiteSpareInfo"];
            lineLabel.font = [UIFont systemFontOfSize:15];
            [lineView addSubview:lineLabel];
            int j = 0;
            for (NSString *string in lineDic) {
                
                UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
                lineLabel.font = [UIFont systemFontOfSize:13];
                lineLabel.text = [NSString stringWithFormat:@"%@",string];
                [lineView addSubview:lineLabel];
                
                UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
                numberLabel.font = [UIFont systemFontOfSize:13];
                numberLabel.text = [NSString stringWithFormat:@"%@",lineDic[string]];
                [lineView addSubview:numberLabel];
                j++;
                
            }
            
            NSInteger  lineTotal = 0;
            for (NSString *string in lineDic) {
                lineTotal = lineTotal + [lineDic[string] intValue];
            }
            UILabel *lineTotalNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
            lineTotalNumberLabel.font = [UIFont systemFontOfSize:13];
            lineTotalNumberLabel.text = [THMangerTool language:@"newOrder.OnSiteSpareTotal"];
            [lineView addSubview:lineTotalNumberLabel];
            
            UILabel *lineTotalLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
            lineTotalLabel.font = [UIFont systemFontOfSize:13];
            lineTotalLabel.text = [NSString stringWithFormat:@"%ld",lineTotal];
            [lineView addSubview:lineTotalLabel];
        }
        
    }else {
        UIView *defectiveView = [[UIView alloc]initWithFrame:CGRectMake(0, 70, submitView.bounds.size.width, 155)];
        defectiveView.backgroundColor = [UIColor whiteColor];
        [submitView addSubview:defectiveView];
        
        UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, defectiveView.bounds.size.width, defectiveView.bounds.size.height)];
        scrollView.delegate = self;
        scrollView.backgroundColor = [UIColor whiteColor];
        scrollView.alwaysBounceVertical = YES;
        
        UILabel *defectiveLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 20)];
        defectiveLabel.text = [UtilCheck language:@"Order.FaultyUnitInfo"];
        defectiveLabel.font = [UIFont systemFontOfSize:15];
        
        [scrollView addSubview:defectiveLabel];
        
        int j = 0;
        for (NSString *string in messageDic) {
            
            UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
            messageLabel.font = [UIFont systemFontOfSize:13];
            messageLabel.text = [NSString stringWithFormat:@"%@",string];
            [scrollView addSubview:messageLabel];
            
            UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
            numberLabel.font = [UIFont systemFontOfSize:13];
            numberLabel.text = [NSString stringWithFormat:@"%@",messageDic[string]];
            scrollView.contentSize = defectiveLabel.bounds.size;
            [scrollView addSubview:numberLabel];
            j++;
            
        }
        NSInteger  messageTotal = 0;
        for (NSString *string in messageDic) {
            
            messageTotal = messageTotal + [messageDic[string] intValue];
        }
        
        UILabel *messageLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
        messageLabel.font = [UIFont systemFontOfSize:13];
        messageLabel.backgroundColor = [UIColor whiteColor];
        messageLabel.text = [THMangerTool language:@"show.totalCount"];
        [scrollView addSubview:messageLabel];
        
        UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
        numberLabel.font = [UIFont systemFontOfSize:13];
        numberLabel.text = [NSString stringWithFormat:@"%ld",messageTotal];
        [scrollView addSubview:numberLabel];
        j++;
        if (lineDic.count >= 1){
            UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 20 * j + 30, submitView.bounds.size.width, lineDic.count * 20 + 55)];
            lineView.backgroundColor = [UIColor whiteColor];
            [scrollView addSubview:lineView];
            
            UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 5, 200, 20)];
            lineLabel.text = [THMangerTool language:@"newOrder.UseOnSiteSpareInfo"];
            lineLabel.font = [UIFont systemFontOfSize:15];
            [lineView addSubview:lineLabel];
            int j = 0;
            for (NSString *string in lineDic) {
                
                UILabel *lineLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
                lineLabel.font = [UIFont systemFontOfSize:13];
                lineLabel.text = [NSString stringWithFormat:@"%@",string];
                [lineView addSubview:lineLabel];
                
                UILabel *numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
                numberLabel.font = [UIFont systemFontOfSize:13];
                numberLabel.text = [NSString stringWithFormat:@"%@",lineDic[string]];
                [lineView addSubview:numberLabel];
                j++;
                
            }
            
            NSInteger  lineTotal = 0;
            for (NSString *string in lineDic) {
                lineTotal = lineTotal + [lineDic[string] intValue];
            }
            UILabel *lineTotalNumberLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 20 * j + 30, defectiveView.bounds.size.width - 80, 20)];
            lineTotalNumberLabel.font = [UIFont systemFontOfSize:13];
            lineTotalNumberLabel.text = [THMangerTool language:@"newOrder.OnSiteSpareTotal"];
            [lineView addSubview:lineTotalNumberLabel];
            
            UILabel *lineTotalLabel = [[UILabel alloc]initWithFrame:CGRectMake(defectiveView.bounds.size.width - 30, 20 * j + 30, 50, 20)];
            lineTotalLabel.font = [UIFont systemFontOfSize:13];
            lineTotalLabel.text = [NSString stringWithFormat:@"%ld",lineTotal];
            [lineView addSubview:lineTotalLabel];
            scrollView.contentSize = CGSizeMake(submitView.bounds.size.width, lineView.bottom);
            
            [defectiveView addSubview:scrollView];
        }else {
            scrollView.contentSize = CGSizeMake(submitView.bounds.size.width, numberLabel.bottom);
            [defectiveView addSubview:scrollView];
        }
        
    }
    
    
    // 确认和修改
    UIView *confirmView = [[UIView alloc]initWithFrame:CGRectMake(0, submitView.bounds.size.height - 38, submitView.bounds.size.width / 2 - 1, 40)];
    confirmView.backgroundColor = [UIColor whiteColor];
    [submitView addSubview:confirmView];
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    confirmButton.frame = confirmView.bounds;
    //CGRectMake((confirmView.bounds.size.width - 50) / 2, (confirmView.bounds.size.height - 20) / 2, 50, 20);
    [confirmButton setTitle:[THMangerTool language:@"CreatingOrders.Confirm"] forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UtilCheck hexStringToColor:@"12a9d1" alpha:1] forState:UIControlStateNormal];
    [confirmButton addTarget:self action:@selector(confirm) forControlEvents:UIControlEventTouchUpInside];
    [confirmView addSubview:confirmButton];
    
    UIView *modifyView = [[UIView alloc]initWithFrame:CGRectMake(submitView.bounds.size.width / 2, submitView.bounds.size.height - 38, submitView.bounds.size.width / 2, 40)];
    modifyView.backgroundColor = [UIColor whiteColor];
    [submitView addSubview:modifyView];
    
    UIButton *modifyButton = [UIButton buttonWithType:UIButtonTypeCustom];
    modifyButton.frame = modifyView.bounds;//CGRectMake((confirmView.bounds.size.width - 50) / 2, (confirmView.bounds.size.height - 20) / 2, 50, 20);
    [modifyButton setTitle:[THMangerTool language:@"CreatingOrders.Modify"] forState:UIControlStateNormal];
    [modifyButton setTitleColor:[UtilCheck hexStringToColor:@"12a9d1" alpha:1] forState:UIControlStateNormal];
    [modifyButton addTarget:self action:@selector(modify) forControlEvents:UIControlEventTouchUpInside];
    
    [modifyView addSubview:modifyButton];
    

    
//    }
}

#pragma  mark 确认提交
- (void)confirm{
    
    
    
    NSMutableArray *receiveGoodArray = [[NSMutableArray alloc]init];
    
    NSLog(@"%@",pieceArray);
    
    for (NSDictionary *dic in pieceArray) {
        
        NSLog(@"每一条的数据%@",dic);
        
        NSMutableDictionary *tmpDict = [[NSMutableDictionary alloc]init];
        if (dic.count > 9){
            
            [tmpDict setValue:[dic objectForKey:@"rma"] forKey:@"rma"];
            [tmpDict setValue:[dic objectForKey:@"name"] forKey:@"name"];
            [tmpDict setValue:[dic objectForKey:@"id"] forKey:@"id"];
            [tmpDict setValue:[dic objectForKey:@"code"] forKey:@"code"];
            [tmpDict setValue:[dic objectForKey:@"versionCode"] forKey:@"versionCode"];
            if ([dic objectForKey:@"sn"]) {
                [tmpDict setValue:[dic objectForKey:@"sn"] forKey:@"sn"];
            }else {
                [tmpDict setValue:@"" forKey:@"sn"];
            }
            [tmpDict setValue:[dic objectForKey:@"detail"] forKey:@"detail"];
            [tmpDict setValue:[dic objectForKey:@"number"] forKey:@"number"];
            [tmpDict setValue:[dic objectForKey:@"isUseOneLine"] forKey:@"isUseOneLine"];
            [tmpDict setValue:[dic objectForKey:@"stationName"] forKey:@"stationName"];
            [tmpDict setValue:[dic objectForKey:@"siteID"] forKey:@"siteID"];
    
            NSMutableDictionary *tmpOneLineDict = [[NSMutableDictionary alloc]init];
            
            [tmpOneLineDict setValue:[dic objectForKey:@"oneLineName"] forKey:@"name"];
            [tmpOneLineDict setValue:[dic objectForKey:@"oneLineCode"] forKey:@"code"];
            [tmpOneLineDict setValue:[dic objectForKey:@"oneLineOneLineVersion"] forKey:@"oneLineVersion"];
            [tmpOneLineDict setValue:[dic objectForKey:@"oneLineOneLineSN"] forKey:@"oneLineSN"];
            [tmpOneLineDict setValue:[dic objectForKey:@"oneLineID"] forKey:@"id"];
            
            [tmpDict setValue:tmpOneLineDict forKey:@"oneLineInfo"];
            NSLog(@"有一线备件的数据 ==== %@",tmpDict);
            
            [receiveGoodArray addObject:tmpDict];
            
        }else {
            
            [tmpDict setValue:[dic objectForKey:@"rma"] forKey:@"rma"];
            [tmpDict setValue:[dic objectForKey:@"name"] forKey:@"name"];
            [tmpDict setValue:[dic objectForKey:@"id"] forKey:@"id"];
            [tmpDict setValue:[dic objectForKey:@"code"] forKey:@"code"];
            [tmpDict setValue:[dic objectForKey:@"versionCode"] forKey:@"versionCode"];
            [tmpDict setValue:[dic objectForKey:@"sn"] forKey:@"sn"];
            [tmpDict setValue:[dic objectForKey:@"detail"] forKey:@"detail"];
            [tmpDict setValue:[dic objectForKey:@"isUseOneLine"] forKey:@"isUseOneLine"];
            [tmpDict setValue:[dic objectForKey:@"stationName"] forKey:@"stationName"];
            [tmpDict setValue:[dic objectForKey:@"siteID"] forKey:@"siteID"];
        
            NSLog(@"无一线备件的数据 ==== %@",tmpDict);
            
            [receiveGoodArray addObject:tmpDict];
            
        }
        
        NSLog(@"拼接的数据%@",receiveGoodArray);
       
    }
    
    managerPostDic = [NSMutableDictionary dictionary];
    
    if (self.dict != nil) {
        [managerPostDic setValue:self.dict[@"orderStatus"][@"orderCode"] forKey:@"orderCode"];
        
    }
    //    [managerPostDic setValue:@"1"forKey:@"orderType"];
    [managerPostDic setValue:dataDic forKey:@"receiveGood"];
    [managerPostDic setValue:receiveGoodArray forKey:@"failureParts"];
    if (delivery == 1) {
        [managerPostDic setValue:@"是" forKey:@"isSameTime"];
    }
    else {
        [managerPostDic setValue:@"否" forKey:@"isSameTime"];
    }
    [managerPostDic setValue:remark forKey:@"remark"];
    [managerPostDic setValue:timeInput forKey:@"takeZheTime"];

    NSLog(@"备件替换服务%@ ",managerPostDic);
    
    [[BDHUD sharedManager] showBDHUD:self.view title:nil];
    [AFHttpTool postJsonDatawithUrl:@"insertOrder_partsManager"  parameters:managerPostDic success:^(id responseObject) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if(1 == [[[responseObject objectForKey:@"head"] objectForKey:@"status"] intValue]) {
            
            NSString *info = [[responseObject objectForKey:@"head"] objectForKey:@"info"];
            
            if ([UtilCheck DataIsNuLL:info]) {
                
                info = [UtilCheck language:@"setting.cogeAdd"];
            }
            [[BDHUD sharedManager] showWords:info];
            [self.navigationController popViewControllerAnimated:YES];
            
        }
        else {
            //返回数据出问题 弹出服务器返回信息
            if([[[responseObject objectForKey:@"head"] allKeys] containsObject:@"info"]&&![UtilCheck DataIsNuLL:[[responseObject objectForKey:@"head"] objectForKey:@"info"]]){
                [[BDHUD sharedManager] showWords:[[responseObject objectForKey:@"head"] objectForKey:@"info"]];
            }
        }
        
    } fail:^(id responseObject, NSError *error) {
        
        [[BDHUD sharedManager] dismissHUD];
        
        if ([[error.userInfo objectForKey:@"NSLocalizedDescription"] isEqualToString:@"请求超时。"]) {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.time.out"]];
        }else {
            [[BDHUD sharedManager] showWords:[UtilCheck language:@"order.network.interruption"]];
        }
        
    }];

}

#pragma  mark 继续修改
- (void)modify{
    [shadowView removeFromSuperview];
}

- (void)shadow{
    [shadowView removeFromSuperview];
}

@end
